package com.sls.web.manager.action.ekhui;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.sls.web.manager.action.SuperAction;
import com.sls.web.manager.common.Constants;
import com.sls.web.manager.common.DateUtil;
import com.sls.web.manager.game.client.OperatorClient;
import com.sls.web.manager.game.client.TraderClient;
import com.sls.web.manager.game.pojo.ekhui.Operator;
import com.sls.web.manager.game.pojo.ekhui.Trader;
import com.sls.web.manager.game.querybean.ekhui.OperatorQuery;
import com.sls.web.manager.page.Pagination;
import com.sls.web.manager.pojo.UserInfoVO;

public class OperatorAction extends SuperAction{
	private Operator operator ;
	private Trader trader ;
	private OperatorQuery operatorQuery ;
	private List<Operator> operatorList ;
	private String startTime ;
	private String endTime ;
	private int recordCount ;
	private Pagination<Operator> page;
	private boolean isAdd ;
	public String list(){
		UserInfoVO userInfoVO = getCurrentOperator() ;
		OperatorClient client = OperatorClient.getInstance() ;
		if(operator == null){
			operator = new Operator() ;
		}
		if (operatorQuery == null) {
			operatorQuery = new OperatorQuery();
			operatorQuery.setPageSize(Constants.INIT_PAGESIZE);
			operatorQuery.setCurrentPage(Constants.INIT_CURRENTPAGE);
		}
		recordCount = client.getOperatorCount(userInfoVO, operator, startTime, endTime) ;
		if(page == null){
			page = new Pagination<Operator>(operatorQuery.getCurrentPage() , recordCount , operatorQuery.getPageSize()) ;
		}
		operatorList = client.getOperatorList(userInfoVO, operator, startTime, endTime, operatorQuery.getCurrentPage(), operatorQuery.getPageSize()) ;
		page.setList(operatorList) ;
		page.setRowCount(recordCount) ;
		return "list" ;
	}
	public String add(){
		TraderClient client = TraderClient.getInstance() ;
		UserInfoVO userInfoVO = getCurrentOperator() ;
		trader = client.getTrader(userInfoVO, trader) ;
		return "add" ;
	}
	public String addComplete(){
		TraderClient client = TraderClient.getInstance() ;
		UserInfoVO userInfoVO = getCurrentOperator() ;
		trader = client.getTrader(userInfoVO, trader) ;
		OperatorClient operatorClient = OperatorClient.getInstance() ;
		operatorClient.addOperator(userInfoVO, operator, trader) ;
		redirectionUrl = "operator!list.htm" ;
		return SUCCESS;
	}
	public String toedit(){
		UserInfoVO userInfoVO = getCurrentOperator() ;
		OperatorClient operatorClient = OperatorClient.getInstance() ;
		operator = operatorClient.queryByIdClient(userInfoVO, operator) ;
		return "add" ;
	}
	public String edit(){
		UserInfoVO userInfoVO = getCurrentOperator() ;
		OperatorClient operatorClient = OperatorClient.getInstance() ;
		operatorClient.edit(userInfoVO, operator) ;
		redirectionUrl = "operator!list.htm" ;
		return SUCCESS;
	}
	public String enableOrDis(){
		UserInfoVO userInfoVO = getCurrentOperator() ;
		OperatorClient operatorClient = OperatorClient.getInstance() ;
		message = String.valueOf(operatorClient.enableOrDis(userInfoVO, operator)) ;
		return "ajax" ;
	}
	public Operator getOperator() {
		return operator;
	}
	public void setOperator(Operator operator) {
		this.operator = operator;
	}
	public OperatorQuery getOperatorQuery() {
		return operatorQuery;
	}
	public void setOperatorQuery(OperatorQuery operatorQuery) {
		this.operatorQuery = operatorQuery;
	}
	public List<Operator> getOperatorList() {
		return operatorList;
	}
	public void setOperatorList(List<Operator> operatorList) {
		this.operatorList = operatorList;
	}
	public String getStartTime() {
		if(StringUtils.isBlank(startTime)){
			startTime = DateUtil.getTodayBegin() ;
		}
		return startTime;
	}
	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}
	public String getEndTime() {
		if(StringUtils.isBlank(endTime)){
			endTime = DateUtil.getTodayEnd() ;
		}
		return endTime;
	}
	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}
	public int getRecordCount() {
		return recordCount;
	}
	public void setRecordCount(int recordCount) {
		this.recordCount = recordCount;
	}
	public Pagination<Operator> getPage() {
		return page;
	}
	public void setPage(Pagination<Operator> page) {
		this.page = page;
	}
	public Trader getTrader() {
		return trader;
	}
	public void setTrader(Trader trader) {
		this.trader = trader;
	}
	public boolean getAdd() {
		return isAdd;
	}
	public void setAdd(boolean isAdd) {
		this.isAdd = isAdd;
	}
}
